﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace WPS.SDK.model.yunfile
{
    /// <summary>
    /// 云文件类
    /// </summary>
    public class FileInfo
    {
        public string fname;
        public string fileid;
        public string ftype;
        public long result;
        public long ctime;
        public long mtime;

        public static FileInfo fromJsonObject(JObject jsonObject)
        {
            FileInfo fileInfo = new FileInfo();
            JObject fileInfoObject = JsonConvert.DeserializeObject<JObject>(jsonObject["data"].ToString());
            if (fileInfoObject == null)
            {
                return fileInfo;
            }
            fileInfo.fname = fileInfoObject["fname"].ToString();
            fileInfo.fileid =  fileInfoObject["fileid"].ToString() ;
            fileInfo.ftype = fileInfoObject["file_type"]==null?"" : fileInfoObject["file_type"].ToString();
            fileInfo.result = Convert.ToInt64(jsonObject["result"].ToString());
            if (fileInfoObject["ctime"]!=null)
            {
                fileInfo.ctime = Convert.ToInt64(fileInfoObject["ctime"].ToString());
            }
            if (fileInfoObject["mtime"] != null)
            {
                fileInfo.mtime = Convert.ToInt64(fileInfoObject["mtime"].ToString());
            }
            return fileInfo;
        }
    }
}
